package de.gdgkarlsruhe.programminfo;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

/**
 * 
 * @author GDG Karlsruhe
 */
public class Track {
	
	private static final String TAG = "Track";
	
	private String title;
	private String speaker;
	
  public String getTitle() {
    return title;
  }
  public void setTitle(String title) {
    this.title = title;
  }
  public String getSpeaker() {
    return speaker;
  }
  public void setSpeaker(String speaker) {
    this.speaker = speaker;
  }
	
  public static Track fromJSONObject(JSONObject jsonObject) throws JSONException {
	Track item = null;
	if (null != jsonObject) {
		item = new Track();
		item.setTitle(jsonObject.getString("title"));
		
		//optional
		try {
			String speaker = jsonObject.getString("speaker");
			if (null != speaker) {
				item.setSpeaker(speaker);
			} else {
				item = null; // nicht in Liste aufnehmen
			}
		} catch (JSONException e) {
			Log.d(TAG, "no speaker details");
			item = null; // nicht in Liste aufnehmen
		}
	}
	return item;
}  
  
  public static List<Track> getDemoData() {
    List<Track> tracks = new ArrayList<Track>();
    for (int i = 0; i < 10; ++i) {
      Track t = new Track();
      t.setTitle("Title " + i);
      t.setSpeaker("Speaker " + i);
      tracks.add(t);
    }
    return tracks;
  }
}
